//
//  HHBaseTabBarController.m
//  HHBroker
//
//  Created by He Wei on 8/26/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "HHBaseTabBarController.h"

@interface HHBaseTabBarController ()

@end

@implementation HHBaseTabBarController

- (void)dealloc
{
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    }
    return self;
}

- (void)customizeTabBarViewControllers
{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"TabControllers" ofType:@"plist"];
    // DLog(@"path : %@", path);
    
    NSArray *array = [NSArray arrayWithContentsOfFile:path];
    NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
    
    for (int i=0; i<array.count; i++) {
        NSDictionary *dict = [array objectAtIndex:i];
        NSString *title = [dict objectForKey:@"title"];
        NSString *imageName = [dict objectForKey:@"iconName"];
        NSString *normalName = [imageName stringByAppendingString:@"_normal"];
        NSString *selectedName = [imageName stringByAppendingString:@"_selected"];
        
        // create viewControllers
        Class class = NSClassFromString([dict objectForKey:@"className"]);
        UIViewController *controller;
        
        
        controller = [[class alloc] init];
        
        
        controller.title = title;
        
        // pvc.navigationItem.title = title;
        // TODO instead of by CRNavigationController
        UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:controller];
        [viewControllers addObject:naviController];
        
        // create UITabBarItem
        UITabBarItem *tabBarItem = nil;
        
        tabBarItem = [[UITabBarItem alloc] initWithTitle:controller.title image:[[UIImage imageNamed:normalName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ] selectedImage:[[UIImage imageNamed:selectedName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        controller.tabBarItem = tabBarItem;
        
        
        controller.tabBarController.view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        // tabBarItem.titlePositionAdjustment = UIOffsetMake(5, 5);
    }
    
    self.viewControllers = viewControllers;
    
    
   
    
    // self.tabBar.translucent = NO;
    self.tabBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    
    //    self.tabBar.clipsToBounds = YES;
    //    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
    // self.tabBar.tintColor = [UIColor redColor];
    // self.tabBar.hidden = YES;
    
    //    self.imageIcon = [[UIImageView alloc] init];
    //    self.imageIcon.backgroundColor = kJiaYuanColor;
    //    self.imageIcon.layer.masksToBounds =YES;
    //    self.imageIcon.layer.cornerRadius = 4;
  
}





- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self customizeTabBarViewControllers];
}



@end
